

// //  获取用户个人信息
// axios({
//     method:'GET',
//     url:'http://api-breakingnews-web.itheima.net/my/userinfo',
//     // 自定义请求头
//     headers:{Authorization:localStorage.getItem('token')}
//     }).then(({data:res})=>{
//     console.log(res);
//     //  判断请求成功
//     if(res.status === 0){
//             let  {id,username,nickname,email,user_pic} = res.data
//             console.log(id,username,nickname,email,user_pic);
//             $('input[name=username]').val(username)
//             $('input[name=nickname]').val(nickname)
//             $('input[name=email]').val(email)   
//     }
//     })

// //  获取用户个人信息简写
function selfUser() {
    axios.get('http://api-breakingnews-web.itheima.net/my/userinfo',{headers:{Authorization:localStorage.getItem('token')}}).then(({data:res})=>{
        console.log(res);
        if(res.status === 0){
            let {id,username,nickname,email,user_pic} = res.data
            // console.log(id,username,nickname,email,user_pic);
            $('input[name=username]').val(username)
            $('input[name=nickname]').val(nickname)
            $('input[name=email]').val(email)        
            $('input[name=id]').val(id)
    }
    })
  }
  selfUser()

$('form').on('submit',(e)=>{
    e.preventDefault()
    axios.post('http://api-breakingnews-web.itheima.net/my/userinfo',$('form').serialize(),{headers:{Authorization:localStorage.getItem('token')}}).then(({data:res})=>{
        console.log(res);
        if(res.status === 0){
            window.parent.getUserInfo()
        }
    })
})
 //重置按钮
$('.my-reset').on('click',(e)=>{
    e.preventDefault()
    selfUser()
})
let form = layui.form;
form.verify({ // 指定规则名和对应的验证规则
    nickname: [ // 昵称
        /^[\u4E00-\u9FA5]+$/,  // 大于等于1
        '昵称只能是中文'
    ],
})

